import React, {Component} from 'react';
import { Router, Route, Redirect, IndexRoute, browserHistory, hashHistory } from 'react-router';
import { connect } from 'react-redux';

import login from '../Component/login'; 

class Roots extends Component {
    render() {
        return (
            <div>{this.props.children}</div>
        );
    }
}

const history = process.env.NODE_ENV !== 'production' ? browserHistory : hashHistory;

const main = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/main').default)
    },'main')
}

const orderall = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/order/orderall').default)
    },'orderall')
}
const ordergoing = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/order/ordergoing').default)
    },'ordergoing')
}
const orderfinish = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/order/orderfinish').default)
    },'orderfinish')
}
const ordercanceling = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/order/ordercanceling').default)
    },'ordercanceling')
}
const ordercancel = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/order/ordercancel').default)
    },'ordercancel')
}

const account = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/account').default)
    },'account')
}
const accountupdate = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/accountupdate').default)
    },'accountupdate')
}
const profileall = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/profile/profileall').default)
    },'profileall')
}
const profilepending = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/profile/profilepending').default)
    },'profilepending')
}
const profilepass = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/profile/profilepass').default)
    },'profilepass')
}
const profilenopass = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/profile/profilenopass').default)
    },'profilenopass')
}
const profiledetail = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/profile/profiledetail').default)
    },'profiledetail')
}
const invoice = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/invoice').default)
    },'invoice')
}
const invoiceupdate = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/invoiceupdate').default)
    },'invoiceupdate')
}

const clearance = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/orderflow/clearance').default)
    },'clearance')
}
const clearanceupdate = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/orderflow/clearanceupdate').default)
    },'clearanceupdate')
}

const transport = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/orderflow/transport').default)
    },'transport')
}
const transportupdate = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/orderflow/transportupdate').default)
    },'transportupdate')
}
const cost = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/orderflow/cost').default)
    },'cost')
}
const costupdate = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/orderflow/costupdate').default)
    },'costupdate')
}

const issuing = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/orderflow/issuing').default)
    },'issuing')
}

const issuingupdate = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/orderflow/issuingupdate').default)
    },'issuingupdate')
}

const lost = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/lost').default)
    },'lost')
}

const signup = (location, cb) => {
    require.ensure([], require => {
        cb(null, require('../Component/signup').default)
    },'signup')
}

// const requireAuth = (nextState, replace) => {
//     if(!sessionStorage.isok){
//         sessionStorage.setItem("isok",true)
//     }else{
//         history.push("/")
//     }
//      onEnter={requireAuth}
// }

const RouteConfig = (
    <Router history={history}>
        <Route path="/" component={Roots}>
            <IndexRoute component={login} />
            <Route path="main" getComponent={main}>
                <Route path="orderall" getComponent={orderall} />
                <Route path="ordergoing" getComponent={ordergoing} />
                <Route path="orderfinish" getComponent={orderfinish} />
                <Route path="ordercanceling" getComponent={ordercanceling} />
                <Route path="ordercancel" getComponent={ordercancel} />
                <Route path="issuing" getComponent={issuing} />
                <Route path="issuingupdate" getComponent={issuingupdate} />
                <Route path="clearance" getComponent={clearance} />
                <Route path="clearanceupdate" getComponent={clearanceupdate} />
                <Route path="cost" getComponent={cost} />
                <Route path="costupdate" getComponent={costupdate} />
                <Route path="transport" getComponent={transport} />
                <Route path="transportupdate" getComponent={transportupdate} />
                <Route path="profileall" getComponent={profileall} />
                <Route path="profilepending" getComponent={profilepending} />
                <Route path="profilepass" getComponent={profilepass} />
                <Route path="profilenopass" getComponent={profilenopass} />
                <Route path="profiledetail" getComponent={profiledetail} />
                <Route path="invoice" getComponent={invoice} />
                <Route path="invoiceupdate" getComponent={invoiceupdate} />
                <Route path="account" getComponent={account} />
                <Route path="accountupdate" getComponent={accountupdate} />
            </Route>
            <Route path="lost" getComponent={lost} />
            <Route path="signup" getComponent={signup} />
            <Redirect from='*' to='/'  />
        </Route>
    </Router>
);

export default RouteConfig;
// export default connect((state) => {
//     const { authReducer } = state;
//     return {
//         authReducer
//     }
// })(RouteConfig);